package net.framework.smc.kafka.service;

import lombok.extern.slf4j.Slf4j;
import net.framework.smc.kafka.channel.MySource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.support.MessageBuilder;

@Slf4j
@EnableBinding(MySource.class)
public class KafkaSender {

    @Autowired
    private MySource mySource;

    public void send(String message){
        log.info("发送数据==========" + message);
        mySource.output().send(MessageBuilder.withPayload(message).build());
    }

    @StreamListener(Processor.INPUT)
    public void receive(@Payload String message) {
        log.info("结果返回==============="+ message);
    }
}
